﻿/****************************************************************************************************************
*                                                                                                               *
* Copyright (C) 2011 5173.com                                                                                   *
* This project may be copied only under the terms of the Apache License 2.0.                                    *
* Please visit the project Home Page http://bqqapicsharp.codeplex.com/ for more detail.                         *
*                                                                                                               *
****************************************************************************************************************/

namespace BQQAPIClient.TestConsole
{
    using System;
    using System.Text;
    using BQQAPIClient.Core;
    using BQQAPIClient.Core.Business;
    using System.Collections.Generic;
    using System.Threading;
     
    class Program
    {
        static void Main(string[] args)
        {
            //Timer t = new Timer(state =>
            //{
            //    Console.Clear();
            //    Console.WriteLine(string.Format("CurrentTime\t{0}", DateTime.Now));
            //    Console.WriteLine(string.Format("ServerStartDateTime\t{0}", BQQAPI.ServerPerformanceCounter.ServerStartDateTime));

            //    Console.WriteLine(string.Format("PerSecondBytesReceived\t{0}", BQQAPI.ServerPerformanceCounter.PerSecondBytesReceived));
            //    Console.WriteLine(string.Format("TotalBytesReceived\t{0}", BQQAPI.ServerPerformanceCounter.TotalBytesReceived));

            //    Console.WriteLine(string.Format("PerSecondBytesSent\t{0}", BQQAPI.ServerPerformanceCounter.PerSecondBytesSent));
            //    Console.WriteLine(string.Format("TotalBytesSent\t{0}", BQQAPI.ServerPerformanceCounter.TotalBytesSent));

            //    Console.WriteLine(string.Format("PerSecondReceiveConut\t{0}", BQQAPI.ServerPerformanceCounter.PerSecondReceiveConut));
            //    Console.WriteLine(string.Format("TotalReceiveCount\t{0}", BQQAPI.ServerPerformanceCounter.TotalReceiveCount));

            //    Console.WriteLine(string.Format("PerSecondSentConut\t{0}", BQQAPI.ServerPerformanceCounter.PerSecondSentConut));
            //    Console.WriteLine(string.Format("TotalSentCount\t{0}", BQQAPI.ServerPerformanceCounter.TotalSentCount));
            //}, null, 0, 1000);


            //  传入客服QQ号，返回工号
            BQQAPI.AssignKefuFunc = qq =>
            {
                Console.WriteLine("分配客服成功！");
                return 1002;
            };

            // 获取客服状态
            BQQAPI.GetAllKefuStatusAction = list =>
            {
                StringBuilder sb = new StringBuilder();
                list.ForEach(item => sb.Append(item.ToString() + Environment.NewLine));
                Console.WriteLine(sb.ToString());
            };

            BQQAPI.KefuStatusNotifyAction = list =>
            {
                StringBuilder sb = new StringBuilder();
                list.ForEach(item =>
                {
                    sb.Append("收到客服状态切换通知：" + item.ToString() + Environment.NewLine);
                    //if (item.KefuStatusEnum == KefuStatusEnum.Online)
                    //{
                    //    BQQAPI.SetKefuStatus(new KefuStatus
                    //    {
                    //        IsHostBySystem = 1,
                    //        KefuID = item.KefuID,
                    //        KefuStatusEnum = KefuStatusEnum.Online,
                    //        MaxAutoAssignCount = 30,
                    //    });
                    //    sb.Append("初始化客服状态成功！" + Environment.NewLine);
                    //}
                });
                Console.WriteLine(sb.ToString());
            };

            Console.WriteLine("开始服务...");
            BQQAPI.Start();

            //Console.WriteLine("设置客服状态...");
            //BQQAPI.SetKefuStatus(new KefuStatusList { new KefuStatus()
            //{
            //    IsHostBySystem = 1,
            //    MaxAutoAssignCount = 11,
            //    KefuID = 1001,
            //    KefuStatusEnum = KefuStatusEnum.Online,
            //}, new KefuStatus()
            //{
            //    IsHostBySystem = 1,
            //    MaxAutoAssignCount = 12,
            //    KefuID = 1002,
            //    KefuStatusEnum = KefuStatusEnum.Left,
            //}});

            //Console.WriteLine("获取所有客服状态...");
            //BQQAPI.GetAllKefuStatus();

            Console.ReadLine();

            Console.WriteLine("停止服务...");
            BQQAPI.Stop();
        }
    }
}